//
//  FaQiShenPiTuPianTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/3/15.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "FaQiShenPiTuPianTableViewCell.h"
#import "ShangChuanTuPianCollectionViewCell.h"
@implementation FaQiShenPiTuPianTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _mainCollcetionView.delegate = self;
    _mainCollcetionView.dataSource = self;
    [_mainCollcetionView registerNib:[UINib nibWithNibName:@"ShangChuanTuPianCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"ShangChuanTuPianCollectionViewCell"];

}

- (void)setModel:(AllModel *)model{
    _model = model;
    _dataArray = model.imageArray;
    NSInteger row = _dataArray.count/3;
    if(_dataArray.count%3 != 0){
        row++;
    }
    _mainCollectionViewHeight.constant = row*(((ScreenWidth-16)/3-16)*78/104+16);
    [_mainCollcetionView reloadData];
    
    [self setupAutoHeightWithBottomView:_mainCollcetionView bottomMargin:0];
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return _dataArray.count;
}
//创建cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ShangChuanTuPianCollectionViewCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ShangChuanTuPianCollectionViewCell" forIndexPath:indexPath];
    NSDictionary *dataDic = _dataArray[indexPath.row];
    if([[dataDic allValues] count] > 0){
        cell.deleteButton.hidden = NO;
        [cell.itemImage sd_setImageWithURL:WebImagePath(GetHandleString(dataDic, @"urlImage"))];
    }else{
        cell.deleteButton.hidden = YES;
        cell.itemImage.image = LocalImagePath(@"跟进记录上传图片");
    }
    
    cell.deleteClickBlock = ^{
        if(_manageClickBlock){
            _manageClickBlock(dataDic,0);
        }
    };
        
    return cell;
}

//设置item的大小
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((ScreenWidth-16)/3, ((ScreenWidth-16)/3-16)*78/104+16);
}
//设置垂直间距,默认的垂直和水平间距都是10
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 0;
}
//设置水平间距
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 0;
}

//四周的边距
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 8, 0, 8);
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *dataDic = _dataArray[indexPath.row];
    if([[dataDic allValues] count] == 0){
        if(_manageClickBlock){
            _manageClickBlock([NSDictionary dictionary],2);
        }
    }else{
        if(_manageClickBlock){
            _manageClickBlock(dataDic,1);
        }
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
